import axios from './axios'
import qs from 'qs'
import {baseUrl} from '@/config/config'
var teacherUrl = baseUrl + '/bdc/api/app/teacher'
// 获取科目 /bdc/api/app/subject/subjectsBySchoolId
export const getSubject = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/bdc/api/app/school/' + params.schoolId + '/subjects',
            method: 'get',
            params
        }).then(res => {
            resolve(res.data)
        })
    })
}
// 获取教职工列表
export const getTeacherList = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl,
            method: 'get',
            params
        }).then(res => {
          resolve(res.data)
        })
    })
}
// 新增教职工信息
export const addTeacher = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl,
            method: 'post',
            data: params
        }).then(res => {
            resolve(res.data)
        }).catch(
            res => {
                reject(res)
            }
        )
    })
}
// 获取单个教职工信息
export const getOneTeacher = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl + '/' + params.id,
            method: 'get'
        }).then(res => {
          resolve(res.data)
        })
    })
}
// 更新单个教职工信息
export const editOneTeacher = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl + '/' + params.id + '/info',
            method: 'put',
            data: params
        }).then(res => {
          resolve(res.data)
        })
    })
}
// 删除单个教职工信息
export const delOneTeacher = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl + '/' + params.id,
            method: 'delete'
        }).then(res => {
          resolve(res.data)
        })
    })
}
// 批量导入教师 /bdc/api/app/school/fsdf/teachers
export const importTeacher = (data) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/bdc/api/app/school/' + data.schoolId + '/teachers',
            method: 'post',
            data: data.body
        }).then(res => {
            resolve(res.data)
        }).catch(
            res => {
                reject(res)
            }
        )
    })
}
// 导出教职工信息excel
export const exportExcel = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: teacherUrl + '/exportExcel',
            method: 'post',
            data: params
        }).then(res => {
            resolve(res.data)
        })
    })
}
// 改变职籍状态 /bdc/api/app/users/{id}/record
export const changeStatus = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/bdc/api/app/users/' + params.id + '/record',
            method: 'post',
            data: params.param
        }).then(res => {
            resolve(res.data)
        })
    })
}
